﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var uid = login.UserName;
            var pwd = login.Password;
            login.FailureText = "";

            var sql = string.Format("select * from Users where Username ='{0}'", uid);
            var dt = DbHelper.GetTable(sql);

            if (dt.Rows.Count == 1)
            {
                var item = dt.Rows[0];
                var password = item.ItemArray[2].ToString();
                var IsActived = (bool)item.ItemArray[3];
                var IsDeleted = (bool)item.ItemArray[4];

                if (pwd == password)
                {
                    if (IsActived)
                    {
                        if (!IsDeleted)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else {
                            login.FailureText = "该账户已被删除，如有疑问请联系客服人员";
                        }
                    }
                    else {
                        login.FailureText = "该账户已被冻结，如有疑问请联系客服人员";
                    }
                }
                else {
                    login.FailureText = "账号或密码错误，请确认后重新登录";
                }

            }
            else {
                login.FailureText = "该账户不存在，请确认后重新登录";
            }
        }
    }
}